<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../three.min.js"></script>
    <script src="../Stats.js" data-ke-src="../Stats.js"></script>
    <script src="../OBJLoader.js"></script>
</head>
<body>
    <script>
        const width = window.innerWidth
        const height = window.innerHeight
        var obj = undefined;
        var renderer = new THREE.WebGLRenderer()
        renderer.setSize(width,height)
        document.body.appendChild(renderer.domElement)

        var scene = new THREE.Scene()

        var camera = new THREE.PerspectiveCamera(60,width/height,1,2000)
        camera.position.set(100,300,600)
        camera.lookAt(scene.position)

        var light = new THREE.DirectionalLight(0xffffff)
        light.position.set(1,1,1)
        scene.add(light)

        var gride = new THREE.GridHelper(1000,50,"blue",0xeeeeee)
        scene.add(gride)


        var group = undefined;

        var objBoxGeometry;
        var LoadingManager = new THREE.LoadingManager()
        var objLoader = new THREE.OBJLoader(LoadingManager)
        objLoader.load("mode/model.obj",
            function(temp) {
                obj = temp
                BoxGeometry = new THREE.BoxHelper(obj)
                /* 计算中心坐标 */
                var box3 = new THREE.Box3().setFromObject(obj)
                let centerPosition = new THREE.Vector3(0,0,0)
                box3.getCenter(centerPosition)

                group = new THREE.Object3D()
                group.add(obj)
                //使得obj和group同一位置
                obj.position.copy(centerPosition.multiplyScalar(-1))
                group.position.copy(centerPosition.multiplyScalar(-1))
                //console.log(box3.getCenter(centerPosition))
                //box3.center(obj)
                scene.add(BoxGeometry)
                console.log(BoxGeometry)
                scene.add(group)
                
                //console.log(obj.position)
            })
        function animation() {
            requestAnimationFrame(animation)
            if(obj!=undefined) {
                group.rotation.y+=0.05
            }
            
            renderer.render(scene,camera)
        }
        animation()
    </script>
</body>
</html>